package com.wwl.open.task;

import com.wwl.open.entity.Monitor;
import com.wwl.open.service.MonitorService;
import com.wwl.open.util.ResourceMonitorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class MonitorTask {
    final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private MonitorService monitorService;

    /**
     * 每隔1分钟执行一次定时任务
     */
    @Scheduled(fixedRate = 5000)
    public void executeTask() {
        Monitor latestMonitor = ResourceMonitorUtil.getLatestMonitor();
        monitorService.createMonitor(latestMonitor);
    }
}
